﻿using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
//用户实体模型
namespace LinqModel.Models
{
    public class User
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }//作用：设置id自增且主键

        [Required]
        [StringLength(50)]
        public string Username {  get; set; }
        
        [Required]
        [EmailAddress]
        [StringLength(100)]
        public string Email { get; set; }


        [Required]
        [Range(18,120)]
        public int Age { get; set; }

        public DateTime CreateAt { get; set; }=DateTime.Now;
        public DateTime? UpdateAt { get; set; }
        public bool IsActive { get; set; } = true;
    }
    public class CreateUserRequest
    {
        [Required(ErrorMessage ="用户名是必填的")]
        [StringLength(20,ErrorMessage ="用户名不能超过{1}个字符")]
        public string Username { get; set; }

        [Required]
        [EmailAddress(ErrorMessage ="请输入有效的电子邮件")]
        public string Email { get; set; }

        [Range(18,120,ErrorMessage ="年龄必须在{1}到{2}之间")]
         public int Age { get; set; }



    }
}
